package com.xjt.feignsentinel.service.impl;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.xjt.feignsentinel.service.FeignService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: xu
 * @Description: TODO
 * @Date: 2021/11/14 22:35
 */
public class FallBackFeignService implements FallbackFactory<FeignService>
{
//	@Override
//	public String test2()
//	{
//		return "当前服务降级了";
//	}
//
//	public String test()
//	{
//		return "服务降级了";
//	}

	public static String testFlowSentinel(BlockException e)
	{
		System.out.println(e.getRule());
		return "当前服务已经熔断降级了";
	}

	@Override
	public FeignService create(Throwable throwable)
	{
		return new FeignService()
		{
			@Override
			public String test2()
			{
				if(throwable instanceof FlowException)
				{
					return "当前服务流控降级处理了";
				}
				return "熔断处理了";
			}

			@Override
			public String test()
			{
				if(throwable instanceof FlowException)
				{
					return "当前服务流控降级处理了";
				}else if(throwable instanceof DegradeException)
				{
					return "熔断降级处理";
				}
				return "熔断处理了";
			}
		};
	}
}
